<?php require_once('../Connections/locale.php'); ?>
<?php
mysql_select_db($database_locale, $locale);
$query_indirizzi = $_POST['query'];
$indirizzi = mysql_query($query_indirizzi, $locale) or die(mysql_error());
$row_indirizzi = mysql_fetch_assoc($indirizzi);
$totalRows_indirizzi = mysql_num_rows($indirizzi);
?>
<? 


//echo $query_indirizzi;


require_once('../includes/html2fpdf.php');

error_reporting(1);






// activate Output-Buffer:


//ob_start(); 

$pdf = new HTML2FPDF('Landscape');
$pdf->DisableTags();
//$pdf->Orientation('Landscape');

$righe = 1;
$colonne = 1;


//echo $query;
 
$xml_output="";

$xml_output .="<table border=1>";
$xml_output .="<tr height=119px>";
$pdf->AddPage();

do { 




if ($colonne > 4) {
	$colonne = 1;
	$righe += 1;
	$xml_output .="</tr>";
	$xml_output .="<tr height=219px>";
}

$xml_output .="<td width=260px height=159px>";
$xml_output .="<center><strong>".$row_indirizzi['nominativo']."</strong><br>";
$xml_output .=$row_indirizzi['indirizzo']."<br>";
$xml_output .=$row_indirizzi['cap']." ".$row_indirizzi['nome_citta']." (".$row_indirizzi['sigla_provincia'].") <br>";
$xml_output .=$row_indirizzi['nome_stato']."<br>";
$xml_output .="</center></td>";

$colonne += 1;

if ($righe > 4) {
	$colonne = 1;
	$righe = 1;
	$xml_output .= "</table>";
	$pdf->WriteHTML($xml_output);
	$pdf->AddPage();
	$xml_output .="<table border=1>";
}







 } while ($row_indirizzi = mysql_fetch_assoc($indirizzi)); 

if ($colonne < 4) {
	$xml_output .="<td colspan=".(4-$colonne+1).">&nbsp;</td></tr></table>";
}
if ($righe < 4) {
	$xml_output .="</tr></table>";
}



//echo $xml_output;




$pdf->WriteHTML($xml_output);
$pdf->Output('test.pdf','D'); 
//echo $xml_output;

?>
 
<?php
mysql_free_result($indirizzi);
?>
